import { AppCfg } from "../../AppCfgs";
import { GameCtx } from "../../GameCtx";
import { Game2048_Data } from "../2048/Game2048_Data";
import { BaseData } from "./BaseData";

export class PlayerData extends BaseData{
    private constructor(){
        super()
    }
    private static _instance: PlayerData = null;
    public static get ins(): PlayerData {
        if (this._instance == null) {
            this._instance = new PlayerData();
        }
        return this._instance;
    }

    private _game2048: Game2048_Data = new Game2048_Data(this);
    public get game2048(): Game2048_Data {
        return this._game2048;
    }

    private _gameWuziqi: Game2048_Data = new Game2048_Data(this);
    public get gameWuziqi(): Game2048_Data {
        return this._gameWuziqi;
    }


    getDataKey(): string {
        return "PlayerData"
    }

    
    loadData(): void {
        if(GameCtx.ins.dataFrom==="local"){
            this.loadDataFromStorege();
            return
        }
        this.loadDataFromServer()
    }
    /**从远程拉取数据 */
    loadDataFromServer() {
        
    }
    /**从本地拉取数据 */
    loadDataFromStorege() {
        this.game2048.loadData()
    }
    //全量保存
    saveData(): void {
        if(GameCtx.ins.dataFrom==="local"){
            for(const key in this) {
                if (this.hasOwnProperty(key)) {
                    const data = this[key];
                    if (data instanceof BaseData) {
                        data.saveData();
                    }
                }
            }
            return
        }
        // this.saveDataToServer()  
    }
}